from bs4 import BeautifulSoup
import requests

s = 0
for count in range(1, 200):
    req = requests.get(r'http://www.mzitu.com/zipai/comment-page-%d/#comments' % count)
    bs = BeautifulSoup(req.text,"html.parser")
    L = []
    t = 0
    for i in bs.find_all('img'):
        if t < 18:
            L.append(i.attrs['src'])
        else:
            break
        t += 1
    for each in L:
        print(each)
        try:
            pic = requests.get(each, timeout=3)
        except requests.exceptions.ConnectionError:
            print('【错误】当前图片无法下载')
            continue
        string = 'D:\\mzitu\\' + str(s) + '.jpg'
        fp = open(string, 'wb')
        fp.write(pic.content)
        fp.close()
        s += 1